cmake_minimum_required(VERSION 2.8)

#project name
project(libtrmpp)

if(NOT CMAKE_BUILD_TYPE)
    message("default to Release build for GCC builds")
    set(CMAKE_BUILD_TYPE Release CACHE STRING
        "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel."
        FORCE)
endif()

#generate build version
execute_process(COMMAND bash ${CMAKE_CURRENT_SOURCE_DIR}/version.sh)

if(CMAKE_BUILD_TARGET STREQUAL ndk)
    message("set ndk toolchain")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error -DLOG_TAG=libtrmpp")
    add_compile_options(-DLINUX)
    add_compile_options(-DANDROID_VNDK)
endif()

if(CMAKE_BUILD_TARGET STREQUAL buildroot)
    message("set buildroot toolchain")
    set(CMAKE_TOOLCHAIN_FILE 
        ${CMAKE_SOURCE_DIR}/buildroot.cmake)
    include(${CMAKE_SOURCE_DIR}/buildroot.cmake)
    add_compile_options(-DLINUX)
    set(CMAKE_CXX_FLAGS "-std=c++11 -O2 -pthread")
endif()

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUN_NEED_GL")

if(CMAKE_BUILD_TARGET STREQUAL ndk)
    string(REPLACE "-DANDROID" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
endif()

# The additional / is important to remove the last character from the path.
# Note that it does not matter if the OS uses / or \, because we are only
# saving the path size.
string(LENGTH "${CMAKE_SOURCE_DIR}/" SOURCE_PATH_SIZE)
add_definitions("-DSOURCE_PATH_SIZE=${SOURCE_PATH_SIZE}")

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-string-plus-int")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-string-plus-int")

include_directories(
    ${CMAKE_CURRENT_SOURCE_DIR}/
    ${CMAKE_CURRENT_SOURCE_DIR}/include
    ${CMAKE_CURRENT_SOURCE_DIR}/src 
    ${CMAKE_CURRENT_SOURCE_DIR}/src/base
    ${CMAKE_CURRENT_SOURCE_DIR}/src/codec/rkmpp/include
    ${CMAKE_CURRENT_SOURCE_DIR}/src/gal_engine
    ${CMAKE_CURRENT_SOURCE_DIR}/src/gal_engine/OpenCL/include
    ${CMAKE_CURRENT_SOURCE_DIR}/src/gal_engine/OpenGL/include
    ${CMAKE_CURRENT_SOURCE_DIR}/src/gal_engine/rkrga/
    ${CMAKE_CURRENT_SOURCE_DIR}/src/gal_engine/rkrga/include
    ${CMAKE_CURRENT_SOURCE_DIR}/src/gal_engine/vulkan/include
    ${CMAKE_CURRENT_SOURCE_DIR}/examples
    ${CMAKE_CURRENT_SOURCE_DIR}/examples/vdec
    ${CMAKE_CURRENT_SOURCE_DIR}/examples/common
    )

link_directories(
    ${CMAKE_CURRENT_SOURCE_DIR}/lib
)

#aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/src MPP_SRCS)
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/src MPP_SRCS)
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/src/base MPP_SRCS)
#message(${CMAKE_CURRENT_SOURCE_DIR})
if(CMAKE_BUILD_TYPE STREQUAL Debug)
#set(LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/lib/debug)
set(LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/lib)
else()
#set(LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/lib/release)
set(LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/lib)
endif()

add_library(trmpp STATIC ${MPP_SRCS})
#add_library(trmpp SHARED ${MPP_SRCS})

#target_link_libraries(trmpp
#    libthirdparty.a
#    pthread
#    dl
#    rt
#)

#build mpp test
#aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/examples MPP_DEMO_SRCS)
#set(MPP_DEMO_SRCS
#    examples/mpp_test.c)

aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/examples/common MPP_DEMO_SRCS)
#aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/examples/vdec MPP_DEMO_SRCS)

if(CMAKE_BUILD_TYPE STREQUAL Debug)
#set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib/debug)
#set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/lib/debug)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/lib)
else()
#set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/lib/release)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/lib)
endif()

add_executable(vdec_test ${CMAKE_CURRENT_SOURCE_DIR}/examples/vdec/sample_vdec.c ${MPP_DEMO_SRCS})
#add_executable(mpptest examples/mpp_test.c)

target_link_libraries(vdec_test
    trmpp
    android
    log)

#install(TARGETS mpptest trmpp DESTINATION /home/diak2/nfs_files/ldh/tmp)
#install(TARGETS mpptest trmpp DESTINATION /home/diak2/nfs_files/ldh/tmp2)